#include "bar.h"

#define FILE 1024*1024*1024
//模拟下载场景
void download(funbar bar)
{
//模拟下载场景
    double rate = 0;
    int total = FILE;
    int downloaded = 0;
    srand(time(NULL)^1920);
    while(total)
    {
        //下载
        usleep(10000);
        int loadspeed = rand()%(1024*1024*2);
        total -= loadspeed;
        if(total < 0)
        {
            total = 0;
        }

        //下载比率
        downloaded = FILE - total;
        rate = ((downloaded*1.0)/(FILE))*100.0;
        //printf("downrate:%.1f%%\n",rate);
        bar(rate);
    }
}
int main()
{
    //processbar();

    download(processbar_2);
    //processbar_2();
    return 0;
}
